module(
    name = "hermetic_cc_toolchain",
    version = "3.2.0",
)

bazel_dep(name = "bazel_features", version = "1.20.0")
bazel_dep(name = "platforms", version = "0.0.8")

bazel_dep(name = "rules_go", version = "0.45.1", dev_dependency = True)

go_sdk = use_extension(
    "@rules_go//go:extensions.bzl",
    "go_sdk",
    dev_dependency = True,
)
use_repo(go_sdk, "go_default_sdk")

bazel_dep(name = "gazelle", version = "0.35.0", dev_dependency = True)

go_deps = use_extension(
    "@gazelle//:extensions.bzl",
    "go_deps",
    dev_dependency = True,
)
go_deps.from_file(go_mod = "//:go.mod")
use_repo(
    go_deps,
    "com_github_bazelbuild_buildtools",
    "com_github_stretchr_testify",
    "com_github_tetratelabs_wazero",
)

toolchains = use_extension("//toolchain:ext.bzl", "toolchains")
use_repo(toolchains, "zig_sdk", "zig_sdk-linux-amd64", "zig_sdk-linux-arm64", "zig_sdk-macos-amd64", "zig_sdk-macos-arm64", "zig_sdk-windows-amd64")

_COMMON_EXEC_PLATFORMS = [
    ("linux", "amd64"),
    ("linux", "arm64"),
    ("windows", "amd64"),
    ("macos", "arm64"),
    ("macos", "amd64"),
]

[register_toolchains(
    # if no `--platform` is specified, these toolchains will be used for
    # (linux,darwin,windows)x(amd64,arm64)
    "@zig_sdk-{}-{}//toolchain:linux_amd64_gnu.2.28".format(os, arch),
    "@zig_sdk-{}-{}//toolchain:linux_arm64_gnu.2.28".format(os, arch),
    "@zig_sdk-{}-{}//toolchain:windows_amd64".format(os, arch),
    "@zig_sdk-{}-{}//toolchain:windows_arm64".format(os, arch),
    # "@zig_sdk-{}-{}//toolchain:darwin_amd64".format(os, arch),
    # "@zig_sdk-{}-{}//toolchain:darwin_arm64".format(os, arch),

    # amd64 toolchains for libc-aware platforms:
    "@zig_sdk-{}-{}//libc_aware/toolchain:linux_amd64_gnu.2.28".format(os, arch),
    "@zig_sdk-{}-{}//libc_aware/toolchain:linux_amd64_gnu.2.31".format(os, arch),
    "@zig_sdk-{}-{}//libc_aware/toolchain:linux_amd64_musl".format(os, arch),
    # arm64 toolchains for libc-aware platforms:
    "@zig_sdk-{}-{}//libc_aware/toolchain:linux_arm64_gnu.2.28".format(os, arch),
    "@zig_sdk-{}-{}//libc_aware/toolchain:linux_arm64_musl".format(os, arch),
    # wasm/wasi toolchains
    "@zig_sdk-{}-{}//toolchain:wasip1_wasm".format(os, arch),

    # These toolchains are only registered locally.
    dev_dependency = True,
) for os, arch in _COMMON_EXEC_PLATFORMS]
